/*
 * é Copyright 2011 Romain Marteau, Matthieu Totet
 * 
 *    This file is part of VineaToum.
 *
 *    VineaToum is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    VineaToum is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with VineaToum.  If not, see <http://www.gnu.org/licenses/>.
 *    
 */

package org.vineatoum.business.action.analyse;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;

import org.vineatoum.business.action.abstraction.Action;
import org.vineatoum.business.action.abstraction.Analyse;
import org.vineatoum.business.configuration.MaturityMeasureType;
import org.vineatoum.view.utils.jtablecustom.TableListener;

public class Prelevement extends Analyse {
	private final static String dateLabel = "Date";
	private final static String maturityLabel = "Maturité";
	private final static String measureTypeLabel = "Type de mesure";
	private final static String acidityLabel = "Acidité";
	private final static String estimatedHarvestDateLabel = "Date de vendanges estimée";
	private final static String estimatedYieldLabel = "Rendement estimé";
	private final static String commentLabel = "Commentaires";
	
	private long id;
	private Date date;
	private float maturity;
	private MaturityMeasureType measureType;
	private float acidity;
	private Date estimatedHarvestDate;
	/**
	 * Yield = rendement
	 */
	private float estimatedYield;
	private String comment;
	
	public Prelevement() {
		maturity = 12;
		acidity = 4;
		estimatedYield = 50;
	}
	
	/**
	 * @return the id
	 */
	public long getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(long id) {
		this.id = id;
	}
	/**
	 * @return the date
	 */
	public Date getDate() {
		return date;
	}
	/**
	 * @param date the date to set
	 */
	public void setDate(Date date) {
		this.date = date;
	}
	/**
	 * @return the maturity
	 */
	public float getMaturity() {
		return maturity;
	}
	/**
	 * @param maturity the maturity to set
	 */
	public void setMaturity(float maturity) {
		this.maturity = maturity;
	}
	/**
	 * @return the measureType
	 */
	public MaturityMeasureType getMeasureType() {
		return measureType;
	}
	/**
	 * @param measureType the measureType to set
	 */
	public void setMeasureType(MaturityMeasureType measureType) {
		this.measureType = measureType;
	}
	/**
	 * @return the acidity
	 */
	public float getAcidity() {
		return acidity;
	}
	/**
	 * @param acidity the acidity to set
	 */
	public void setAcidity(float acidity) {
		this.acidity = acidity;
	}
	/**
	 * @return the estimatedHarvestDate
	 */
	public Date getEstimatedHarvestDate() {
		return estimatedHarvestDate;
	}
	/**
	 * @param estimatedHarvestDate the estimatedHarvestDate to set
	 */
	public void setEstimatedHarvestDate(Date estimatedHarvestDate) {
		this.estimatedHarvestDate = estimatedHarvestDate;
	}
	/**
	 * @return the estimatedYield
	 */
	public float getEstimatedYield() {
		return estimatedYield;
	}
	/**
	 * @param estimatedYield the estimatedYield to set
	 */
	public void setEstimatedYield(float estimatedYield) {
		this.estimatedYield = estimatedYield;
	}
	/**
	 * @return the comment
	 */
	public String getComment() {
		return comment;
	}
	/**
	 * @param comment the comment to set
	 */
	public void setComment(String comment) {
		this.comment = comment;
	}
	@Override
	public TableListener getNewInstance() {
		return new Prelevement();
	}
	@Override
	public Vector<String> getVectorColumns() {
		Vector<String> vector = new Vector<String>();
		vector.add(dateLabel);
		vector.add(maturityLabel);
		vector.add(measureTypeLabel);
		vector.add(acidityLabel);
		vector.add(estimatedHarvestDateLabel);
		vector.add(estimatedYieldLabel);
		vector.add(commentLabel);
		return vector;
	}
	@Override
	public Vector<Object> getVectorData() {
		SimpleDateFormat  simpleFormat = new SimpleDateFormat("dd MMMMM yyyy");
		DecimalFormat df = new DecimalFormat("########.##"); 
		
		Vector<Object> vector = new Vector<Object>();
		if(date != null)
			vector.add(simpleFormat.format(date));
		else
			vector.add("");
		vector.add(df.format(maturity));
		vector.add(measureType);
		vector.add(df.format(acidity));
		if(estimatedHarvestDate != null)
			vector.add(simpleFormat.format(estimatedHarvestDate));
		else
			vector.add("");
		vector.add(df.format(estimatedYield));
		vector.add(comment);
		return vector;
	}
	@Override
	public void updateField(String field, Object value) {
		try {
			if (field.equals(dateLabel)) {
				this.date = (Date) value;
			} else if (field.equals(maturityLabel)) {
				this.maturity = (Float) value;
			} else if (field.equals(measureTypeLabel)) {
				this.measureType = (MaturityMeasureType) value;
			} else if (field.equals(acidityLabel)) {
				this.acidity = (Float) value;
			} else if (field.equals(estimatedHarvestDateLabel)) {
				this.estimatedHarvestDate = (Date) value;
			} else if (field.equals(estimatedYieldLabel)) {
				this.estimatedYield = (Float) value;
			} else if (field.equals(commentLabel)) {
				this.comment = (String) value;
			} 
		} catch (ClassCastException e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
}
